package com.ruoyi.salary.services.impl;

import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.salary.domain.EmployeeSalary;
import com.ruoyi.salary.mapper.SystemSalaryMapper;
import com.ruoyi.salary.services.ISysSalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.Collection;
import java.util.List;

/**
 * 参数配置 服务层实现
 * 
 * @author ffc
 */
@Service
public class SysSalaryServiceImpl implements ISysSalaryService
{
    @Autowired
    private SystemSalaryMapper salaryMapper;

    @Autowired
    private RedisService redisService;

    /**
     * 项目启动时，初始化参数到缓存
     */
    @PostConstruct
    public void init()
    {
        loadingConfigCache();
    }

    /**
     * 查询参数配置信息
     * 
     * @param salaryId 参数配置ID
     * @return 参数配置信息
     */
    @Override
    public EmployeeSalary selectSalaryById(Long salaryId)
    {
        EmployeeSalary salary = new EmployeeSalary();
        salary.setSalaryId(salaryId);
        return salaryMapper.selectSalaryById(salary);
    }

    @Override
    public EmployeeSalary selectSalaryById(Long salaryId,Long userId)
    {
        EmployeeSalary salary = new EmployeeSalary();
        salary.setUserId(userId);
        salary.setSalary(salaryId);
        return salaryMapper.selectSalaryById(salary);
    }

    @Override
    public List<EmployeeSalary> selectSalary(EmployeeSalary salary) {
        return salaryMapper.selectSalaryList(salary);
    }

    @Override
    public int insertSalary(EmployeeSalary salary) {
        return 0;
    }

    @Override
    public int updateSalary(EmployeeSalary salary) {
        return 0;
    }

    @Override
    public void deleteSalaryByIds(Long[] salaryIds) {

    }

    @Override
    public void loadingConfigCache() {

    }


    /**
     * 清空参数缓存数据
     */
    @Override
    public void clearConfigCache()
    {
        Collection<String> keys = redisService.keys(CacheConstants.SYS_CONFIG_KEY + "*");
        redisService.deleteObject(keys);
    }

    /**
     * 重置参数缓存数据
     */
    @Override
    public void resetConfigCache()
    {
        clearConfigCache();
        loadingConfigCache();
    }

    @Override
    public boolean checkSalaryUnique(EmployeeSalary salary) {
        return false;
    }


    /**
     * 设置cache key
     * 
     * @param configKey 参数键
     * @return 缓存键key
     */
    private String getCacheKey(String configKey)
    {
        return CacheConstants.SYS_CONFIG_KEY + configKey;
    }
}
